#pragma once

#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
extern "C"
{
#include <stdint.h>
#include "x264.h"
}


#define FRAME_WIDTH 1280
#define FRAME_HEIGHT 720
#define VENC_FPS 30


struct X264Encoder
{
	x264_t* m_pX264Handle;
	x264_param_t* m_pX264Param;

	x264_picture_t* m_pX264Pic_out;
	x264_picture_t* m_pX264Pic_in;
	x264_nal_t* m_pX264Nals;
	int m_x264iNal;
	FILE* m_x264Fp;
};


class H264Captor
{
public:
	H264Captor();
	~H264Captor();
	
	cv::VideoCapture* videoCapture;
	cv::Mat* cameraFrame;
	X264Encoder* x264Encoder;

	int initH264Captor();
	void encodeCamFrame();

	int initX264Encoder(X264Encoder& x264Encoder);
	void convertFrameToX264Img(x264_image_t* x264InImg, cv::Mat& frame);
	void encoderImg(X264Encoder& x264Encoder, cv::Mat& frame);

	void testX264();
};

